#include <vmm.h>
#include <host_syscall.h>
#include <proc.h>

bool
copy_from_user(struct mm_struct *mm, void *dst, const void *src, size_t len, bool writable) {
    if (!user_mem_check(mm, (uintptr_t)src, len, writable)) {
        return 0;
    }
	if (mm == NULL)
		memcpy(dst, src, len);
	else if (host_getvalue (current, (uintptr_t)src, dst) < 0)
		return 0;
    return 1;
}

bool
copy_to_user(struct mm_struct *mm, void *dst, const void *src, size_t len) {
    if (!user_mem_check(mm, (uintptr_t)dst, len, 1)) {
        return 0;
    }
	if (mm == NULL)
		memcpy(dst, src, len);
	else if (host_assign (current, (uintptr_t)dst, *(uintptr_t *)src) < 0)
		return 0;
	return 1;
}
